﻿

app.controller('HomeController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;
    $scope.GoPage = function (menuid) {
        mui.showLoading("正在跳转..", "div");
        $http({
            method: 'POST',
            url: '../Account/MGetMenuRole',
            data: { "MenuId": menuid }
        })
            .success(function (ret) {
                mui.hideLoading();
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    if (ret.Data == "") {
                        mui.toast("暂无权限访问该界面");
                    }
                    else {
                        location.href = ret.Data;;
                    }
                }
                else {
                    return false;
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitMenubar = function () {
        $scope.height = window.innerHeight - 105;
    }

    $scope.InitPage = function () {
        $scope.ParkList = [];
        $http({
            method: 'POST',
            url: '../Home/GetDefaultRoomId'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ChangeRoom(ret.Data[0]);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyToken = function () {
        $scope.MyToken = [];
        $http({
            method: 'POST',
            url: '../Account/GetToken'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.MyToken = ret.Data;
                    var linklist = $('[id^="link_"]');
                    for (var i = 0; i < linklist.length; i++) {
                        var link = linklist[i];
                        var href = $(link).attr("href");
                        $(link).attr("href", href.replace('{{MyToken}}', ret.Data));
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetMainMenu = function () {
        mui.showLoading("正在加载..", "div");
        var hmenu = sessionStorage.getItem('HomeMenu');
        if (hmenu == null) {
            $http({
                method: 'POST',
                url: '../Account/GetMMenuList',
                data: { 'Node': 0 }
            })
                .success(function (ret) {
                    mui.hideLoading();
                    common.success($scope, null, ret);
                    if (ret.Code == 100) {
                        $scope.HomeMenuList = ret.Data;
                        //$compile(htmlcontent)($scope);
                        sessionStorage.setItem("HomeMenu", JSON.stringify(ret.Data));
                    }
                    else {
                        mui.toast(ret.Msg);
                    }
                })
                .error(function (data, status, headers, config) {
                    mui.toast("请检查网络");
                });
        }
        else {
            $scope.HomeMenuList = JSON.parse(hmenu);
            mui.hideLoading();
        }
    }





    $scope.GetParkList = function () {
        $scope.ParkList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetParkList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ParkList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.ShowPicture = function (src) {
        $scope.IsPreview = true;
        $("#imgshow").attr("src", src);
    }
    $scope.ClosePreview = function () {
        $scope.IsPreview = false;
        $("#imgshow").attr("src", "");
    }
    $scope.GetBuildingTreeList = function (Id) {
        $scope.BuildingTreeList = [];
        for (var i = 0; i < $scope.ParkTreeList.length; i++) {
            if ($scope.ParkTreeList[i].Id == Id) {
                $scope.BuildingTreeList = $scope.ParkTreeList[i].BuildingList;
            }
        }
    }

    $scope.GetFloorTreeList = function (Id) {
        $scope.FloorTreeList = [];
        for (var i = 0; i < $scope.ParkTreeList.length; i++) {
            if ($scope.ParkTreeList[i].Id == Id) {
                $scope.BuildingTreeList = $scope.ParkTreeList[i].BuildingList;
            }
        }
    }

    $scope.GetBuildingList = function (id) {
        $scope.BuildingList = [];
        if (id == null || id == "") {
            return false;
        }

        $http({
            method: 'POST',
            url: '../CheckForm/GetBuildingList',
            data: { 'ParkId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.BuildingList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetFloorList = function (id) {
        $scope.FloorList = [];
        if (id == null || id == "") {
            return false;
        }
        $http({
            method: 'POST',
            url: '../CheckForm/GetFloorList',
            data: { 'BuildingId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.FloorList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    
    $scope.GetPlaceListByFloorId = function (id) {
        $scope.RoomList = [];
        if (id == null || id == "") {
            return false;
        }
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetPlaceListByFloorId',
            data: { 'FloorId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.RoomList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetRoomList = function (id) {
        $scope.RoomList = [];
        if (id == null || id == "") {
            return false;
        }
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetRoomList',
            data: { 'FloorId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.RoomList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceResponsibilityByRoomId = function (id) {
        $scope.ResponsibilityList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceResponsibilityByRoomId',
            data: { 'RoomId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ResponsibilityList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceResponsibilityLevelList = function (Id) {
        $scope.DataLoading = true;
        $scope.LevelList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceResponsibilityLevelListByRoomId',
            data: { "RoomId": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.LevelList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetRiskList = function (Id) {
        $scope.DataLoading = true;
        $scope.RiskList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetRiskListByRoomId',
            data: { "RoomId": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.RiskList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceTree = function () {
        $scope.ParkTreeList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetPlaceTree'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ParkTreeList = ret.Data;
                    setTimeout(function () {
                        $('#tree-default').jstree({
                            "types": {
                                "default": {
                                    "icon": "fa fa-folder icon-state-warning icon-lg"
                                },
                                "file": {
                                    "icon": "fa fa-file icon-state-warning icon-lg"
                                }
                            },
                            "plugins": ["types"]
                        }).bind('click.jstree', function (event) {
                            var id = $(event.target).parents('li').attr('id');
                            if (id.indexOf('LINK') != -1) {
                                var roomid = $(event.target).parents('li').attr('data');
                                $scope.ChangeRoom(roomid);
                            }

                        });
                    }, 1000);

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceResponsibilityAttrList = function (Id) {
        $scope.DataLoading = true;
        $scope.AttrList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetResponsibilityAttrListByRoomId',
            data: { 'RoomId': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.AttrList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetDeviceList = function (model, page) {
        $scope.DeviceList = [];
        $http({
            method: 'POST',
            url: '../FacilityAndEquipment/GetFacilityPageList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.DeviceList = ret.Data.Data;
                    $scope.TotalCount = ret.Data.TotalItemCount;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetCheckFormPageList = function (model) {
        $scope.CheckFormPageList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFormList',
            data: { 'model': model },
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckFormPageList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetHiddenTroubleList = function (model) {
        $scope.HiddenTroubleList = [];
        model.StartTime = model.Year + '-01-01';
        model.EndTime = model.Year + "-12-31 23:59:59";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleList',
            data: { 'model': model },
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.HiddenTroubleList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEventReportList = function (model) {
        $scope.EventReportList = [];
        model.StartTime = model.Year + '-01-01';
        model.EndTime = model.Year + "-12-31 23:59:59";
        $http({
            method: 'POST',
            url: '../EventReport/GetEventReportList',
            data: { 'model': model },
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.EventReportList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetEventReportDetail = function (Id) {
        $scope.EventReportDetail = {};
        $http({
            method: 'POST',
            url: '../EventReport/GetEventReportDetail',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.EventReportDetail = ret.Data;
                    $scope.EventReportDetail.ParkId = $scope.EventReportDetail.ParkId + "";
                    //$scope.GetPlaceList('placelist', $scope.EventReportDetail.ParkId, $scope.EventReportDetail.PlaceId);
                    $scope.EventReportDetail.ReportTime = $filter('JSONDate')($scope.EventReportDetail.ReportTime, 'yyyy-MM-dd HH:mm');
                    $scope.EventReportDetail.CheckTime = $filter('JSONDate')($scope.EventReportDetail.CheckTime, 'yyyy-MM-dd HH:mm');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowCompleteSolution = function (Id, model, page, pagename, IsEdit, IsDelete) {
        var control = $("#tr_" + Id);
        if ($("#tr_solution_" + Id).length > 0) {
            $("#tr_solution_" + Id).remove();
        }
        else {
            var htmlcontent = "<tr id='tr_solution_" + Id + "'><td colspan='13'>";
            htmlcontent += '<table class="table table-striped table-bordered table-hover">';
            htmlcontent += '<thead><tr style=""><th style="width:2%">序号</th><th style="width:2%">临时措施</th><th style="width:2%">整改进度</th><th style="width:5%">计划完成时间</th><th style="width:5%">责任人</th><th style="width:15%">措施描述</th><th style="width:10%">操作</th></tr></thead>';
            htmlcontent += '<tbody>';
            if (model.length > 0) {
                for (var i = 0; i < model.length; i++) {
                    htmlcontent += '<tr>';
                    htmlcontent += '<td>' + (i + 1) + '</td>';
                    if (model[i].IsTemporary) {
                        htmlcontent += '<td>是</td>';
                    }
                    else {
                        htmlcontent += '<td>否</td>';
                    }
                    if (model[i].Process == 100) {
                        htmlcontent += '<td>完成</td>';
                    }
                    else {
                        htmlcontent += '<td>未完成</td>';
                    }
                    htmlcontent += '<td>' + $filter('JSONDate')(model[i].PlanCompleteTime, 'yyyy-MM-dd'); +'</td>';
                    htmlcontent += '<td>' + model[i].EmployeeNo + "-" + model[i].EmployeeName + '</td>';
                    htmlcontent += '<td><span">' + ("" + model[i].SolutionContent) + '</span></td>';
                    htmlcontent += '<td><a ng-show="' + IsEdit + '==1" href="SolutionEdit?SolutionId=' + model[i].SolutionId + '&FormId=' + Id + '&page=' + page + '&pagename=' + pagename + '" class="btn btn-default btn-xs btn-label"><i class="fa fa-pencil"></i>编辑</a> <a ng-show="' + IsDelete + '==1" ng-click="DeleteSolution(\'' + model[i].SolutionId + '\');" class="btn btn-danger btn-xs btn-label"><i class="fa fa-trash-o"></i>删除</a></td>';
                    htmlcontent += '</tr>';
                }
            }
            else {
                htmlcontent += "<tr><td colspan='7'>暂无解决措施</td></tr>";
            }
            htmlcontent == '</tbody>';
            htmlcontent += '</table></td></tr>';
            var $html = $compile(htmlcontent)($scope);
            control.after($html);
        }
    }

    $scope.GetHiddenTroubleStateList = function (model) {
        $scope.HiddenTroubleStateList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleState',
            data: { 'model': model },
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.HiddenTroubleStateList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceDepartment = function (placeid, model) {
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckPlaceBasicInfo',
            data: { 'PlaceId': placeid }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    model.DepartmentId = ret.Data.DepartmentId;
                    model.DepartmentName = ret.Data.DepartmentName;
                    model.Manager = ret.Data.DepartmentManager;
                    model.ResponsibleName = ret.Data.UserName;
                    model.Responsible = ret.Data.UserNo;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetCheckFormDetail = function (id) {
        $scope.CheckDetail = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFormDetail',
            data: { 'FormId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckDetail = ret.Data;
                    $scope.CheckDetail.CheckTime = $filter('JSONDate')($scope.CheckDetail.CheckTime, 'yyyy-MM-dd');
                    if ($scope.CheckDetail.PlaceId != 0) {
                        $scope.GetPlaceDepartment($scope.CheckDetail.PlaceId, $scope.CheckDetail);
                        console.log($scope.CheckDetail);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetLocationDetail = function (Id) {
        $scope.LocationDetail = {};
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetLocationDetail',
            data: { 'RoomId': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.LocationDetail = ret.Data;

                    $scope.LocationModel.ParkId = $scope.LocationDetail.ParkInfo.Id + "";
                    $scope.GetBuildingList($scope.LocationModel.ParkId);
                    $scope.LocationModel.BuildingId = $scope.LocationDetail.BuildingInfo.Id + "";
                    $scope.GetFloorList($scope.LocationModel.BuildingId);
                    $scope.LocationModel.FloorId = $scope.LocationDetail.FloorInfo.Id + "";
                    $scope.GetPlaceListByFloorId($scope.LocationModel.FloorId);
                    $scope.LocationModel.RoomId = Id + "";
                    $scope.LocationModel.PlaceId = $scope.LocationDetail.PlaceInfo.Id + "";

                    var obj = {
                        RoomId: $scope.LocationModel.RoomId,
                        PlaceId: $scope.LocationModel.PlaceId,
                        PlaceName: $scope.LocationDetail.PlaceInfo.PlaceName
                    };

                    //var str = $scope.LocationDetail.ParkInfo.ParkName + $scope.LocationDetail.BuildingInfo.BuildingName + $scope.LocationDetail.FloorInfo.FloorName + $scope.LocationDetail.RoomName;
                    var str = JSON.stringify(obj);

                    $('#qrcode').html("")
                    var qrcode = new QRCode(document.getElementById("qrcode"), {
                        width: 60,
                        height: 60
                    });
                    qrcode.makeCode(str);
                }
                else {
                    //alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.ChangeRoom = function (Id) {
        if (Id == null || Id == "")
            return false;
        $scope.GetLocationDetail(Id);
        $scope.GetPlaceResponsibilityByRoomId(Id);
        $scope.GetPlaceResponsibilityLevelList(Id);
        $scope.GetRiskList(Id);
        $scope.GetPlaceResponsibilityAttrList(Id);
        $scope.SearchModel = {};
        $scope.SearchModel.RoomId = Id;
        $scope.GetDeviceList($scope.SearchModel, 1);
        $scope.SearchModel.FormStatus = 1;
        $scope.SearchCheckForm.RoomId = Id;
        $scope.GetCheckFormPageList($scope.SearchCheckForm);
        $scope.SearchH.RoomId = Id;
        $scope.GetHiddenTroubleList($scope.SearchH);
        $scope.SearchEvent.RoomId = Id;
        $scope.GetEventReportList($scope.SearchEvent);
    }


    $scope.GetIncompleteDailyCheckTask = function () {
        $scope.DataLoading = true;
        $scope.DailyCheckTaskList = [];
        $http({
            method: 'POST',
            url: '../Home/GetIncompleteDailyCheckTask'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.DailyCheckTaskList = ret.Data;
                    $scope.IncompleteCount += ret.Data.length;
                    for (var i = 0; i < $scope.DailyCheckTaskList.length; i++) {
                        if ($scope.DailyCheckTaskList[i].OVerdueDays <= 1) {
                            $scope.OverdueCount++;
                        }
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetSepcialCheckTask = function () {
        $scope.SepcialCheckTaskList = [];
        $http({
            method: 'POST',
            url: '../Task/GetSepcialCheckTask'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.SepcialCheckTaskList = ret.Data;
                    $scope.IncompleteCount += ret.Data.length;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetSepcialCheckCompleteTask = function () {
        $scope.SepcialCheckCompleteTaskList = [];
        $http({
            method: 'POST',
            url: '../Task/GetSpecialCheckCompleteTask'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.SepcialCheckCompleteTaskList = ret.Data;
                    $scope.CompleteCount += ret.Data.length;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetTaskCount = function () {

        $http({
            method: 'POST',
            url: '../Task/GetMyTaskCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TaskCount = ret.Data;
                    setTimeout(function () {
                        if (ret.Data > 0) {
                            $("#TaskCount").html(ret.Data);
                        }
                    }, 1000);
                   
                   
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetMyCheckTaskCount = function () {
        $http({
            method: 'POST',
            url: '../Task/GetMyCheckTaskCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.CheckTaskCount = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.GetCompleteDailyCheckTask = function () {
        $scope.DataLoading = true;
        $scope.DailyCheckCompleteTaskList = [];
        $http({
            method: 'POST',
            url: '../Home/GetCompleteDailyCheckTask'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.DailyCheckCompleteTaskList = ret.Data;
                    $scope.CompleteCount += ret.Data.length;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetHiddenTroubleTaskList = function () {
        $scope.HiddenTroubleTaskList = [];
        $http({
            method: 'POST',
            url: '../Task/GetHiddenTroubleTaskList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.HiddenTroubleTaskList = ret.Data;
                    $scope.IncompleteCount += ret.Data.length;
                    for (var i = 0; i < $scope.HiddenTroubleTaskList.length; i++) {
                        if ($scope.HiddenTroubleTaskList[i].EndTime != null) {
                            $scope.OverdueCount++;
                        }
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetIssueReportTaskList = function () {
        $scope.IssueTaskList = [];
        $http({
            method: 'POST',
            url: '../Task/GetIssueReportTaskList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.IssueTaskList = ret.Data;
                    $scope.IncompleteCount += ret.Data.length;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetIssueReportCompleteTaskList = function () {
        $scope.IssueCompleteTaskList = [];
        $http({
            method: 'POST',
            url: '../Task/GetIssueCompleteTask'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.IssueCompleteTaskList = ret.Data;
                    $scope.CompleteCount += ret.Data.length;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetHiddenTroubleCompleteList = function () {
        $scope.HiddenTroubleCompleteList = [];
        $http({
            method: 'POST',
            url: '../Task/GetHiddenTroubleTaskList',
            data: { "IsComplete": true }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.HiddenTroubleCompleteList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetDeviceTask = function () {
        $scope.DeviceTask = [];
        $http({
            method: 'POST',
            url: '../Task/GetDeviceTask'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.DeviceTask = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckCountView = function (model) {
        if (model.Type == 1) {
            $scope.GetDepartmentCheckChart(model);
        }
        else if (model.Type == 2) {
            $scope.GetMonthCheckChart(model.Year);
        }
        else {
            $scope.GetPlaceCheckChart(model);
        }
    }

    $scope.GetDepartmentCheckChart = function (model) {
        $http({
            method: 'POST',
            url: '../CheckForm/GetDepartmentCheckChart',
            data: { "Year": model.Year, "Month": model.Month }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    //var total = [];
                    //var normal = [];
                    var dailycheck = [];
                    var weeklycheck = [];
                    var monthlycheck = [];
                    var dailytask= [];
                    var weeklytask = [];
                    var monthlytask = [];

                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].DepartName);
                        dailycheck.push(datalist[i].DailyCheck);
                        weeklycheck.push(datalist[i].WeekCheck);
                        monthlycheck.push(datalist[i].MonthCheck);
                        dailytask.push(datalist[i].TaskCount[0]);
                        weeklytask.push(datalist[i].TaskCount[1]);
                        monthlytask.push(datalist[i].TaskCount[2]);
                    }
                    var myChart = echarts.init(document.getElementById('countview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 40,
                            right: 25
                        },

                        series: [
                            {
                                name: '应日检',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(145, 146, 166, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 146, 166)",

                                },
                                data: dailytask
                            },
                            {
                                name: '应周检',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(55, 192, 141, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(55, 192, 141)",

                                },
                                data: weeklytask
                            },
                            {
                                name: '应月检',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(255, 165, 0, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(255, 165, 0)",

                                },
                                data: monthlytask
                            },
                            {
                                name: '实日检',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: dailycheck// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '实周检',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(83, 148, 201, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(83, 148, 201)",

                                },
                                data: weeklycheck// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '实月检',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(145, 204, 117, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 204, 117)",

                                },
                                data: monthlycheck// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            }
                            
                            //,
                            //{
                            //    name: '异常',
                            //    type: 'bar',
                            //    stack: "ad",
                            //    itemStyle: {
                            //        color: 'rgba(250, 219, 216, 0.6)',
                            //        borderWidth: 0.5,
                            //        borderColor: "rgba(250, 219, 216)",
                            //    },
                            //    data: exception//[11, 20, 13, 12, 11, 1, 5, 17, 7, 13, 25, 14]
                            //}
                        ], dataZoom: [{
                            // start: 0,//默认为0
                            // end: 100,//默认为100
                            type: 'slider',
                            show: true,
                            // xAxisIndex: [0],
                            handleSize: 0,//滑动条的 左右2个滑动条的大小
                            startValue: 0, // 初始显示值
                            endValue: 20, // 结束显示值
                            height: 20,//组件高度
                            left: '1%', //左边的距离
                            right: '1%',//右边的距离
                            bottom: -15,//底边的距离
                            // borderColor: "#000",
                            fillerColor: 'grey',
                            borderRadius: 5,
                            backgroundColor: '#eee',//两边未选中的滑动条区域的颜色
                            showDataShadow: false,//是否显示数据阴影 默认auto
                            showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
                            realtime: true, //是否实时更新
                            filterMode: 'filter',
                        }]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceCheckChart = function (model) {
        $http({
            method: 'POST',
            url: '../CheckForm/GetPlaceCheckChart',
            data: { "Year": model.Year, "Month": model.Month, "PlaceType": model.PlaceType }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var dailycheck = [];
                    var weeklycheck = [];
                    var monthlycheck = [];
                    var dailytask = [];
                    var weeklytask = [];
                    var monthlytask = [];
                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].PlaceName);
                        dailycheck.push(datalist[i].DailyCheck);
                        weeklycheck.push(datalist[i].WeekCheck);
                        monthlycheck.push(datalist[i].MonthCheck);
                        dailytask.push(datalist[i].TaskCount[0]);
                        weeklytask.push(datalist[i].TaskCount[1]);
                        monthlytask.push(datalist[i].TaskCount[2]);
                    }
                    var myChart = echarts.init(document.getElementById('countview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }
                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 40,
                            right: 25
                        },

                        series: [
                            {
                                name: '应日检',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(145, 146, 166, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 146, 166)",

                                },
                                data: dailytask
                            },
                            {
                                name: '应周检',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(55, 192, 141, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(55, 192, 141)",

                                },
                                data: weeklytask
                            },
                            {
                                name: '应月检',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(255, 165, 0, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(255, 165, 0)",

                                },
                                data: monthlytask
                            },
                            {
                                name: '实日检',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: dailycheck// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '实周检',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(83, 148, 201, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(83, 148, 201)",

                                },
                                data: weeklycheck// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '实月检',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(145, 204, 117, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 204, 117)",

                                },
                                data: monthlycheck// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            }

                        ], dataZoom: [{
                            // start: 0,//默认为0
                            // end: 100,//默认为100
                            type: 'slider',
                            show: true,
                            // xAxisIndex: [0],
                            handleSize: 0,//滑动条的 左右2个滑动条的大小
                            startValue: 0, // 初始显示值
                            endValue: 20, // 结束显示值
                            height: 20,//组件高度
                            left: '1%', //左边的距离
                            right: '1%',//右边的距离
                            bottom: -15,//底边的距离
                            // borderColor: "#000",
                            fillerColor: 'grey',
                            borderRadius: 5,
                            backgroundColor: '#eee',//两边未选中的滑动条区域的颜色
                            showDataShadow: false,//是否显示数据阴影 默认auto
                            showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
                            realtime: true, //是否实时更新
                            filterMode: 'filter',
                        }]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.MGetPlaceCheckChart = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCheckChart',
            data: { "Year": model.Year, "Month": model.Month, "PlaceType": model.PlaceType, "pageSize": 3 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var max = 0;
                    var datalist = ret.Data;
                    var namelist = [];
                    var total = [];
                    var normal = [];
                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].Name);
                        total.push(datalist[i].Total);
                        normal.push(datalist[i].Normal);
                        exception.push(datalist[i].ExCount);
                    }
                    var myChart = echarts.init(document.getElementById('countview1'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 0,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            //{
                            //    name: '计划',
                            //    type: 'bar',

                            //    itemStyle: {
                            //        color: 'rgba(135, 153, 154, 0.7)',
                            //        borderWidth: 0.5,
                            //        borderColor: "rgba(135, 153, 154)",
                            //    },
                            //    data: total//[43, 52, 65, 53, 55, 27, 44, 62, 42, 54, 59]
                            //},
                            {
                                name: '正常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: normal// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '异常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(250, 219, 216, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(250, 219, 216)",
                                },
                                data: exception//[11, 20, 13, 12, 11, 1, 5, 17, 7, 13, 25, 14]
                            }
                        ]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

        $http({
            method: 'POST',
            url: '../Home/GetPlaceCheckChart',
            data: { "Year": model.Year, "Month": model.Month, "PlaceType": model.PlaceType, "pageSize": 3, "Sort": 0 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var max = 0;
                    var datalist = ret.Data;
                    var namelist = [];
                    var total = [];
                    var normal = [];
                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].Name);
                        total.push(datalist[i].Total);
                        normal.push(datalist[i].Normal);
                        exception.push(datalist[i].ExCount);
                        max = datalist[i].Total + 5;
                    }
                    var myChart = echarts.init(document.getElementById('countview2'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 0,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {
                            max: max,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            //{
                            //    name: '计划',
                            //    type: 'bar',

                            //    itemStyle: {
                            //        color: 'rgba(135, 153, 154, 0.7)',
                            //        borderWidth: 0.5,
                            //        borderColor: "rgba(135, 153, 154)",
                            //    },
                            //    data: total//[43, 52, 65, 53, 55, 27, 44, 62, 42, 54, 59]
                            //},
                            {
                                name: '正常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: normal// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '异常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(250, 219, 216, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(250, 219, 216)",
                                },
                                data: exception//[11, 20, 13, 12, 11, 1, 5, 17, 7, 13, 25, 14]
                            }
                        ]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.GetMonthCheckChart = function (year) {
        $http({
            method: 'POST',
            url: '../Home/GetMonthCheckChart',
            data: { "Year": year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var total = [];
                    var normal = [];
                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].Name);
                        total.push(datalist[i].Total);
                        normal.push(datalist[i].Normal);
                        exception.push(datalist[i].ExCount);
                    }
                    var myChart = echarts.init(document.getElementById('countview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 20,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            //{
                            //    name: '计划',
                            //    type: 'bar',
                            //    itemStyle: {
                            //        color: 'rgba(135, 153, 154, 0.7)',
                            //        borderWidth: 0.5,
                            //        borderColor: "rgba(135, 153, 154)",
                            //    },
                            //    data: total//[43, 52, 65, 53, 55, 27, 44, 62, 42, 54, 59]
                            //},
                            {
                                name: '正常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: normal// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '异常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(250, 219, 216, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(250, 219, 216)",
                                },
                                data: exception//[11, 20, 13, 12, 11, 1, 5, 17, 7, 13, 25, 14]
                            }
                        ]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCategoryView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetCategoryView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('typeview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '问题类型分布',
                            type: 'pie',
                            center: ['60%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetParkView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetParkView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('factoryview'));
                var option = {
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '园区分布图',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: '40',
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            color: ['rgb(83,148,201)', 'rgb(55,191,141)', 'orange', 'grey'],
                            data: datalist
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetLevelView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetLevelView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('souceview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '问题等级分布',
                            type: 'pie',
                            center: ['60%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetHiddenTroubleTaskCount = function () {
        $http({
            method: 'POST',
            url: '../Task/GetHiddenTroubleTaskCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.HiddenTroubleTaskCount = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckYearList = function () {
        $http({
            method: 'POST',
            url: '../Home/GetCheckYearList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.CheckYearList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceCountByPark = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByPark'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('parkplaceview'));
                    var datalist = [];
                    for (var i = 0; i < ret.Data.length; i++) {
                        var data = ret.Data[i];
                        var obj = {
                            'name': data.ParkName,
                            'value': data.PlaceNum
                        };
                        datalist.push(obj);
                    }

                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                        },
                        series: [
                            {
                                label: {
                                    position:'outer',
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个,占{d}%',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['50%', '50%'],
                                radius: '50%',
                                data: datalist,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('placetypeview'));

                    var datalist = ret.Data;

                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '70%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个  占{d}%',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#0E5DA6', '#1177DC'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

    }
    $scope.GetDeviceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetDeviceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('devicetypeview'));
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        valuelist.push(data.value);
                        namelist.push(data.name);
                    }
                    var option = {
                        title: {
                            text: ''
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        legend: { show: false },
                        grid: {
                            left: '3%',
                            right: '4%',
                            top: '3%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'value',
                            boundaryGap: [0, 0.01]
                        },
                        yAxis: {
                            type: 'category',
                            data: namelist
                        },
                        series: [
                            {
                                name: '设备数量',
                                type: 'bar',
                                label: {
                                    show: true
                                },
                                data: valuelist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#FF9966'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetUserCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetUserCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('usertypeview'));
                    var datalist = ret.Data;
                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}人',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['60%', '50%'],
                                radius: '70%',
                                data: datalist,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetUserCountByOnline = function () {
        $http({
            method: 'POST',
            url: '../Home/GetUserCountByOnline'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('onlineview'));
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        valuelist.push(data.value);
                        namelist.push(data.name);
                    }
                    var option = {
                        legend: {
                            show: false
                        },
                        tooltip: {},
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,
                            inverse: true,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 20,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            {
                                name: '',
                                type: 'line',
                                smooth: true,
                                itemStyle: {
                                    color: '#0E5DA6',
                                    borderWidth: 2,
                                    borderColor: "rgba(135, 153, 154)",
                                },
                                data: valuelist
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMonthlyCheckChart = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetCheckRecordByType',
            data: { 'PlaceType': model.PlaceType2 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var dailycount = [];
                    var weeklycount = [];
                    var monthlycount = [];
                    var exceptioncount = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].date);
                        dailycount.push(datalist[i].dailycount);
                        weeklycount.push(datalist[i].weeklycount);
                        monthlycount.push(datalist[i].monthlycount);
                        exceptioncount.push(datalist[i].exceptioncount);
                    }
                    var myChart = echarts.init(document.getElementById('checkrecordmonthlyview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            inverse: true,
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            {
                                name: '日检',
                                smooth: true,
                                type: 'line',
                                label: {
                                    show: true
                                },
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(83, 148, 201, 0.7)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(83, 148, 201)",
                                },
                                data: dailycount
                            },
                            {
                                name: '周检',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: weeklycount
                            },
                            {
                                name: '月检',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(145, 201, 117, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 201, 117)",
                                },
                                data: monthlycount
                            },
                            {
                                name: '异常项',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(229, 63, 49, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(229, 63, 49)",
                                },
                                data: exceptioncount
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckNum = function () {
        $scope.CheckCount = [];
        $http({
            method: 'POST',
            url: '../Home/GetCheckRecordCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckCount = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

        $scope.IssueCount = [];
        $http({
            method: 'POST',
            url: '../Home/GetHiddenTroubleRecordCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.IssueCount = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceRiskChart = function (Id) {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceRiskChart',
            data: { "PlaceId": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('riskchart'));

                    var datalist = ret.Data;

                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            show: false
                        },
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['30%', '50%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                   
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


});

app.filter('GetBoolStr', function () { //可以注入依赖
    return function (text) {
        if (text)
            return "在用";
        else
            return "停用";

    }
});

app.filter('HideLongText', function () { //可以注入依赖
    return function (text) {
        if ((text != null || text != "") && text.length > 10) {
            return text.substr(0, 10) + "..."
        }
        else {
            return text;
        }
    }
});